//
//  MainViewController.swift
//  weibo
//
//  Created by William Peng on 16/3/20.
//  Copyright © 2016年 William Peng. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //自定义tabBar,添加加号按钮,系统的tabBar是只读的,不能直接赋值,要用KVC赋值
        self.setValue(MainTabBar(), forKey: "tabBar")
        
        //创建所有的控制器
        addchildViewControllers()
    }
    
        func addchildViewControllers(){
            //用UITabBarController封装在应用程序启动文件中设置的tabBar模型
            
            //设置tabBar子控制器的各种值
            //首页
            let homeVC = HomeViewController()
            addChildViewController(homeVC, title: "首页", imageNname: "tabbar_home")
            
            //消息
            let messageVC = MessageViewController()
            addChildViewController(messageVC, title: "消息", imageNname: "tabbar_message_center")
            
            //发现
            let FaXianVC = FaXianViewController()
            addChildViewController(FaXianVC, title: "发现", imageNname: "tabbar_discover")
            
            //我
            let mysVC = MysViewController()
            addChildViewController(mysVC, title: "我", imageNname: "tabbar_profile")
 
        }
        
    
    
    //修改"添加子控制器"方法的属性
    func addChildViewController(controller: UIViewController, title: String, imageNname: String) {
        //设置标题
        controller.title = title
        //设置普通图片
        controller.tabBarItem.image = UIImage(named: imageNname)
        //拼接图片
        let highlightImageName = imageNname + "_highlighted"
        //设置高亮图片,,,默认情况下选中的图片会被渲染成蓝色.**要设置成图片的颜色
        controller.tabBarItem.selectedImage = UIImage(named: highlightImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置item文字
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        //添加子控制器
        addChildViewController(UINavigationController(rootViewController: controller))
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
